package com.example.demo.controller;

import com.example.demo.model.MessageInfo;
import com.example.demo.service.MessageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageInfoController {
    @Autowired
    private MessageInfoService messageInfoService;
    private List<MessageInfo> messageInfo = new ArrayList<>();
    @RequestMapping("/publish")
    public boolean publish(MessageInfo msg){
        if(!StringUtils.hasLength(msg.getFrom()) || !StringUtils.hasLength(msg.getTo())
                || !StringUtils.hasLength(msg.getMessage())){
            return false;
        }
        messageInfoService.insertMessage(msg);
        return true;
    }
    @RequestMapping("/getList")
    public List<MessageInfo> getList(){
        return messageInfoService.selectAllMessageInfo();
    }
}
